﻿using System;
using System.Collections.Generic;
using System.Text;
using MySql.Data.MySqlClient;
using System.Xml;

namespace Models
{
    public class DBHelper
    {
        private static string sql = getconnstr();
        public static MySqlConnection con = new MySqlConnection(sql);
       
        public static string getconnstr()
        {
            string connstr = "";
            XmlReader xreader = XmlReader.Create("config.xml");
            try
            {
                xreader.Read();
                xreader.ReadStartElement("conn");
                xreader.ReadStartElement("server");
                connstr += "server=" + xreader.ReadString() + ";";
                xreader.ReadEndElement();
                xreader.ReadStartElement("database");
                connstr += "database=" + xreader.ReadString() + ";";
                xreader.ReadEndElement();
                xreader.ReadStartElement("uid");
                connstr += "uid=" + xreader.ReadString() + ";";
                xreader.ReadEndElement();
                xreader.ReadStartElement("pwd");
                connstr += "pwd=" + Encrypt.DecryptDES(xreader.ReadString(),Config.code) + ";";
                xreader.ReadEndElement();
                xreader.ReadStartElement("Charset");
                connstr += "Charset=" + xreader.ReadString();
                xreader.ReadEndElement();
                xreader.Close();
            }
            finally
            { }
            return connstr;
        }
    }
}
